<?php


namespace App\Http\Resources\news;


use App\Models\news\Comment;
use App\Models\news\News;
use Illuminate\Http\Resources\Json\ResourceCollection;

class NewsCommentResource extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (Comment $item) {
                return [
                    'id' => $item->id,
                    'news_id' => $item->news_id??'',
                    'user_id' => $item->user_id,
                    'content' => $item->content,
                    'status' => $item->status??'',
                    'created_at' => $item->created_at->toDateTimeString()??'',
                    'updated_at' => $item->updated_at->toDateTimeString()??'',
                    'name' => $item->user->name,
                    'header_img' => $item->user->header_img,
                    'phone' => $item->user->phone,
                ];
            })
        ];

    }
}